<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){	
            jQuery.validator.addMethod("file_upload_valid", function(value, element, param) {
				var messages = '';
                var returnVal = true;
				if($('#artist_id').find('input:checked').length == 0){
					messages += "- <?php echo lang('artist_relate');?>\n";
				}
				if($('#album_id').find('input:checked').length == 0){
					messages += "- <?php echo lang('album_relate');?>\n";
				} else if($('#album_id').find('input:checked').length > 1){
					messages += "- <?php echo lang('album_relate_default_over');?>\n";
				}
				if(queueSize == 0 && $('#song_embed').val() == ""){
					messages += "- <?php echo lang('song_file');?>\n";
				}
				if($('#video_id').find('li:visible').length > 1){
					messages += "- <?php echo lang('song_video_relate_default_over');?>\n";
				}										
				if(messages){
					jQuery.validator.messages.file_upload_valid = messages.substr(2,(messages.length-2));
					returnVal = false;	
				}						
				return returnVal;
           	}, jQuery.validator.messages.file_upload_valid);					
			
            $("#Form").validate({
				ignore: "",
                rules: {
					media_type_id: "required",
					letters: "required",
					song_name: "required",
					file_upload: {
						file_upload_valid:true
					},
					song_tag: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }				
					var interval = setInterval(function() {
					    if (success_file) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					media_type_id: "<?php echo lang('media_type');?>",
					letters: "<?php echo lang('letters');?>",
					song_name: "<?php echo lang('song_name');?>",
					song_tag: "<?php echo lang('song_tag');?>"					
                }
            });	
		
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.mp3;*.MP3',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });	
			
			$('.genreTag').each(function(){
				$(this).click(function(){
					if($(this).is(':checked')){
						var Delimiter = "";
						var Str = "";
						if($('#genre_tag').val() != "") Delimiter = "/";
						$('#genre_tag').val($('#genre_tag').val()+Delimiter+$(this).next().text());						
					} else {
						$('#genre_tag').val(($('#genre_tag').val().replace(new RegExp($(this).next().text()+"\/"+"|"+"\/"+$(this).next().text()+"$"+"|"+$(this).next().text(),"g"),"")));
					}
				});
			});	

			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});
			
			//DateTime Picker
			$('.datetime').datetimepicker({
				dateFormat:'dd/mm/yy',
				timeFormat:'hh:mm',
				separator:' ',
				changeMonth : true,
				changeYear : true,
				yearRange: '-100y:c+nn',
				maxDate: '-1d',
				showHour: true,		
				showMinute: true,
				showTime: true		
			});						
        });
    })(jQuery);	
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" checked="checked"/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" /> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('song_publish_date');?></th>
							<td><input type="text" name="song_publish_date" id="song_publish_date" class="medium-text datetime" value="<?php echo date('d/m/Y H:i');?>" readonly="readonly"/></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('media_type');?></th>
							<td>
								<select id="media_type_id" name="media_type_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataMediaType as $value):?>
										<option value="<?php echo $value->media_type_id;?>"><?php echo $value->media_type_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('genre');?></th>
							<td>
								<?php if(!empty($dataGenre)):?> 
									<ul class="listItemsHorizontal">
										<?php foreach($dataGenre as $value):?>
										<li>
											<input type="checkbox" name="genre_id[]" value="<?php echo $value->genre_id;?>" class="genreTag"/> <span><?php echo $value->genre_name;?></span>
										</li>
										<?php endforeach;?>
									</ul>
								<?php endif;?>
								<input type="text" name="genre_tag" id="genre_tag" class="regular-text"/> <?php echo lang('editable');?>
							</td>
						</tr>						
<!--						<tr>
							<th scope="row"><?php echo lang('is_show_hot_on_chart');?></th>
							<td>
								<input type="radio" name="is_show_hot_on_chart" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hot_on_chart" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('is_show_hurt_song_mood');?></th>
							<td>
								<input type="radio" name="is_show_hurt_song_mood" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hurt_song_mood" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('is_show_love_song_mood');?></th>
							<td>
								<input type="radio" name="is_show_love_song_mood" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_love_song_mood" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>-->						
						<tr>
							<th scope="row"><?php echo lang('is_show_new_released');?></th>
							<td>
								<input type="radio" name="is_show_new_released" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_new_released" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>						
<!--						<tr>
							<th scope="row"><?php echo lang('is_show_oldie');?></th>
							<td>
								<input type="radio" name="is_show_oldie" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_oldie" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>-->						
						<tr>
							<th scope="row"><?php echo lang('is_show_ost_song_mood');?></th>
							<td>
								<input type="radio" name="is_show_ost_song_mood" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_ost_song_mood" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>						
<!--						<tr>
							<th scope="row"><?php echo lang('is_show_play_song');?></th>
							<td>
								<input type="radio" name="is_show_play_song" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_play_song" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>-->						
						<tr>
							<th scope="row"><?php echo lang('is_show_recommend2');?></th>
							<td>
								<input type="radio" name="is_show_recommend" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_show_recommend" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('letters');?></th>
							<td><input type="text" name="letters" id="letters" class="small-text" maxlength="1"/></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('song_name');?></th>
							<td><input type="text" name="song_name" id="song_name" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('song_description');?></th>
							<td><?php echo display_ckeditor('song_description','',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('song_lyrics');?></th>
							<td><?php echo display_ckeditor('song_lyrics','',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('song_embed');?></th>
							<td><textarea id="song_embed" name="song_embed" rows="5" class="regular-text"></textarea></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('song_tag');?></th>
							<td><input type="text" name="song_tag" id="song_tag" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('artist_relate');?> <a href="<?php echo base_url().'song/content_management/search_artist';?>" class="tools plus search_tools"></a></th>
							<td class="describe">
								<ul id="artist_id" class="listItems">
									<li class="first"><?php echo lang('no_artist_relate');?></li>
								</ul>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('album_relate');?> <a href="<?php echo base_url().'song/content_management/search_album';?>" class="tools plus search_tools"></a></th>
							<td class="describe">
								<ul id="album_id" class="listItems">
									<li class="first"><?php echo lang('no_album_relate');?></li>
								</ul>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('video_relate');?> <a href="<?php echo base_url().'song/content_management/search_video';?>" class="tools plus search_tools"></a></th>
							<td class="describe">
								<ul id="video_id" class="listItems">
									<li class="first"><?php echo lang('no_video_relate');?></li>
								</ul>
							</td>
						</tr>								
						<tr>
							<th scope="row"><?php echo lang('song_file');?></th>
							<td><input type="file" name="file_upload" id="file_upload"/></td>
						</tr>																						
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_add');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->